// write your code here cpp
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    //1. 由于数字太大，需要用string 接受
    while(cin >> s)
    {
        int num = 0;
        //2. 直接对于接收回来的字符串求和
        for(int i = 0;i < s.size();i++)
        {
            num += s[i] - '0';
        }
        int sum = 0;
        while(num)
        {
            sum += num %10;
            num = num / 10;
            if(num == 0 && sum / 10 != 0)
            {
                num = sum;
                sum = 0;
            }
        }
        cout << sum << endl;
    }
    return 0;
}
